package com.wind.sqlite.service.impl;

import com.wind.sqlite.common.base.BaseModelPageDTO;
import com.wind.sqlite.common.utils.PageUtils;
import com.wind.sqlite.common.utils.Query;
import com.wind.sqlite.dao.ProcessConfigTDao;
import com.wind.sqlite.entity.ProcessConfigTEntity;
import com.wind.sqlite.common.base.BaseModelPageDTO;
import com.wind.sqlite.common.utils.PageUtils;
import com.wind.sqlite.common.utils.Query;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import java.util.List;
import com.wind.sqlite.dao.ProcessConfigTDao;
import com.wind.sqlite.entity.ProcessConfigTEntity;
import com.wind.sqlite.service.ProcessConfigTService;


@Service("processConfigTService")
public class ProcessConfigTServiceImpl extends ServiceImpl<ProcessConfigTDao, ProcessConfigTEntity> implements ProcessConfigTService {

  @Autowired
  private  ProcessConfigTDao processConfigTDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProcessConfigTEntity> page = this.page(
                new Query<ProcessConfigTEntity>().getPage(params),
                new QueryWrapper<ProcessConfigTEntity>()
        );
        return new PageUtils(page);
    }

  @Override
  public PageUtils queryPage(BaseModelPageDTO<ProcessConfigTEntity> data) {
    ProcessConfigTEntity entity = data.getData();
    QueryWrapper<ProcessConfigTEntity> queryWrapper = null;
    //分页查询所有
    if(entity==null){
      queryWrapper = new QueryWrapper<ProcessConfigTEntity>();
    }else{
      queryWrapper = new QueryWrapper<ProcessConfigTEntity>();
      queryWrapper = getProcessConfigTEntityQueryWrapper(entity, queryWrapper);
    }
    IPage<ProcessConfigTEntity> page = this.page(
        new Query<ProcessConfigTEntity>().getPage(data),
        queryWrapper
    );
    return new PageUtils(page);
  }

  @Override
  public PageUtils queryPage(ProcessConfigTEntity entity) {
    BaseModelPageDTO<ProcessConfigTEntity> data=new BaseModelPageDTO<ProcessConfigTEntity>();
    data.setData(entity);
    return queryPage(data);
  }

    @Override
    public ProcessConfigTEntity queryOne(ProcessConfigTEntity entity) {
        QueryWrapper<ProcessConfigTEntity> queryWrapper = null;
        //分页查询所有
        if(entity==null){
            queryWrapper = new QueryWrapper<ProcessConfigTEntity>();
        }else{
            queryWrapper = new QueryWrapper<ProcessConfigTEntity>();
            queryWrapper = getProcessConfigTEntityQueryWrapper(entity, queryWrapper);
        }
        return this.baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<ProcessConfigTEntity> query(ProcessConfigTEntity entity) {
        QueryWrapper<ProcessConfigTEntity> queryWrapper = null;
        //分页查询所有
        if(entity==null){
            queryWrapper = new QueryWrapper<ProcessConfigTEntity>();
        }else{
            queryWrapper = new QueryWrapper<ProcessConfigTEntity>();
            queryWrapper = getProcessConfigTEntityQueryWrapper(entity, queryWrapper);
        }
        return this.baseMapper.selectList(queryWrapper);
    }

    private QueryWrapper<ProcessConfigTEntity> getProcessConfigTEntityQueryWrapper(ProcessConfigTEntity entity, QueryWrapper<ProcessConfigTEntity> queryWrapper) {
      if(entity.getId()!=null){
        queryWrapper=queryWrapper.eq("id", entity.getId());
       }
    if(StringUtils.isNotEmpty(entity.getProtocol())){
       queryWrapper=queryWrapper.eq("protocol", entity.getProtocol());
       }
    if(entity.getPort()!=null){
       queryWrapper=queryWrapper.eq("port", entity.getPort());
       }
    if(StringUtils.isNotEmpty(entity.getUsername())){
       queryWrapper=queryWrapper.eq("username", entity.getUsername());
       }
    if(StringUtils.isNotEmpty(entity.getPassword())){
       queryWrapper=queryWrapper.eq("password", entity.getPassword());
       }
        if(entity.getCreateTimeBeginTime()!=null){
           queryWrapper=queryWrapper.ge("create_time", entity.getCreateTimeBeginTime());
           }
        if(entity.getCreateTimeEndTime()!=null){
           queryWrapper=queryWrapper.le("create_time", entity.getCreateTimeEndTime());
           }
        if(entity.getUpdateTimeBeginTime()!=null){
           queryWrapper=queryWrapper.ge("update_time", entity.getUpdateTimeBeginTime());
           }
        if(entity.getUpdateTimeEndTime()!=null){
           queryWrapper=queryWrapper.le("update_time", entity.getUpdateTimeEndTime());
           }
    return queryWrapper;
  }


}